package com.cskaoyan.servlet;

import com.cskaoyan.bean.MarketCategory;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.service.CategoryService;
import com.cskaoyan.service.CategoryServiceImpl;
import com.cskaoyan.util.JacksonUtil;
import lombok.SneakyThrows;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/admin/category/*")
public class AdminCategoryServlet extends WdBaseServlet{

    CategoryService categoryService= new CategoryServiceImpl();
    private BaseRespVo list(HttpServletRequest request, HttpServletResponse response){
        BaseRespVo baseRespVo = categoryService.list();

        return baseRespVo;
    }
    @SneakyThrows
    private BaseRespVo create(HttpServletRequest request, HttpServletResponse response){

        String s = request.getReader().readLine();
        MarketCategory marketCategory = JacksonUtil.read(s, MarketCategory.class);

        BaseRespVo baseRespVo = categoryService.create(marketCategory);
        return baseRespVo;

    }
    @SneakyThrows
    private BaseRespVo update(HttpServletRequest request, HttpServletResponse response){


        String s = request.getReader().readLine();
        MarketCategory marketCategory=JacksonUtil.read(s,MarketCategory.class);

        BaseRespVo baseRespVo = categoryService.update(marketCategory);

        return baseRespVo;

    }
    @SneakyThrows
    private BaseRespVo delete(HttpServletRequest request, HttpServletResponse response){

        String s = request.getReader().readLine();
        MarketCategory marketCategory = JacksonUtil.read(s, MarketCategory.class);

        BaseRespVo baseRespVo = categoryService.delete(marketCategory);

        return baseRespVo;

    }
    private BaseRespVo l1(HttpServletRequest request, HttpServletResponse response){


        BaseRespVo baseRespVo = categoryService.l1();

        return baseRespVo;
    }

}
